// com/yt/product/service/ProductCategoryServiceImpl.java
package com.yt.product.service;

import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import javax.annotation.Resource;
import com.yt.product.common.config.YmlConfig;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yt.product.mapper.ProductCategoryMapper;
import com.yt.product.models.service.IProductCategoryService;
import com.yt.product.models.bo.ProductCategorySaveBO;
import com.yt.product.models.dto.ProductCategoryDTO;

import java.util.Date;
import java.util.List;

@DubboService
public class ProductCategoryServiceImpl extends ServiceImpl<ProductCategoryMapper, ProductCategoryDTO> implements IProductCategoryService{

    @Resource
    private YmlConfig ymlConfig;

    @Override
    public boolean add(ProductCategorySaveBO saveBO) {
        ProductCategoryDTO dto = new ProductCategoryDTO();
        // 手动拷贝字段
        dto.setCategoryName(saveBO.getCategoryName());
        dto.setStatus(saveBO.getStatus());
        dto.setRevision(saveBO.getRevision());

        // 设置时间字段
        dto.setCreateTime(saveBO.getCreatetime() != null ? saveBO.getCreatetime() : new Date());
        dto.setUpdateTime(saveBO.getUpdatetime() != null ? saveBO.getUpdatetime() : new Date());

         //使用数据库自增ID或分布式ID生成策略，而不是固定的ymlConfig.getPkId()
         Long id = ymlConfig.getPkId();
         dto.setId(id);

        return this.insert(dto);
    }

    @Override
    public List<ProductCategoryDTO> selectByIds(List<Long> ids) {
        return baseMapper.selectBatchIds(ids);
    }

    @Override
    public List<ProductCategoryDTO> selectAll() {
        return baseMapper.selectList(null);
    }
}